<template>
  <a-card :bordered="false">
    <v-table
      bordered
      ref="table"
      :columns="columns"
      :data="loadData"
    >
      <span slot="action" slot-scope="{row,text}">
        <a-popconfirm title="是否删除用令牌" @confirm="del(row)" okText="是" cancelText="否">
          <a-icon slot="icon" type="question-circle-o" style="color: red"/>
          <a href="javascript:;" style="color: red">删除</a>
        </a-popconfirm>
      </span>
    </v-table>
  </a-card>
</template>

<script>
import { fetchList, delObj } from '@api/sys/token'
export default {
  name: 'Token',
  data () {
    return {
      alert: {
        clear: true
      },
      queryParam: {},
      loadData: parameter => {
        return fetchList(
          Object.assign(parameter, this.queryParam)
        ).then(res => {
          return res.data
        })
      },
      selectedRowKeys: [],
      selectedRows: [],
      columns: [
        {
          title: '用户ID',
          sorter: true,
          field: 'user_id'
        },
        {
          title: '用户名',
          field: 'username'
        },
        {
          title: '令牌',
          field: 'access_token'
        },
        {
          title: '类型',
          field: 'token_type'
        },
        {
          title: '过期时间',
          field: 'expires_in'
        },
        {
          title: '操作',
          field: 'action',
          slot: true
        }
      ]
    }
  },
  methods: {
    onSelectChange (selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    del (record) {
      delObj(record.access_token).then(res => {
        this.$message.info('删除成功')
        this.$refs.table.refresh(true)
      }).catch(err => {
        this.$message.error(err.msg)
      })
    }
  }
}
</script>

<style scoped>

</style>
